//  home 中间件
import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios'

//  在框架中应用Vuex
Vue.use(Vuex);

export default {
    state: {
        infoList: [],
        max_len: 0,
        pagesize: 3
    },
    mutations: {

    },
    actions: {
        getInfoList({ state }, page) {
           
            let start = (page - 1) * state.pagesize;
            axios({
                method: 'get',
                url: '/data/info_data.json'
            }).then((res) => {
                state.max_len = res.data.data.infoList.length
                if (start < state.max_len) {
                    state.infoList = state.infoList.concat(res.data.data.infoList.slice(start, start + state.pagesize));
                }
            }).catch((err) => {
                console.log(err);
            })
        }
    },
    modules: {
        //  引入其他中间件
    }
}